package com.glory.eapequipmentmonitor.activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.glory.eapequipmentmonitor.R;
import com.glory.eapequipmentmonitor.adapter.EqpThingListAdapter;
import com.glory.eapequipmentmonitor.base.Constant;
import com.glory.eapequipmentmonitor.bean.ThingBean;
import com.glory.eapequipmentmonitor.callback.DeleteCallback;
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_BaseActivity;
import com.pda.platform.ui.ui_pdaplatform.entity.FreeUI_AddViewEntity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class ChangeThingListActivity extends FreeUI_BaseActivity {


    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.tvUser)
    TextView tvUser;
    @BindView(R.id.tvEqpId)
    TextView tvEqpId;
    @BindView(R.id.rvThingList)
    RecyclerView rvThingList;

    private EqpThingListAdapter eqpThingListAdapter;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_change_thing_list;
    }

    @Override
    protected void initView() {
        tvUser.setText(Constant.CURRENT_USER);
        tvEqpId.setText("EQP-001");
        freeUI_titleView.setTitle("更换物料");
        rvThingList.setLayoutManager(new LinearLayoutManager(ChangeThingListActivity.this));
        rvThingList.setItemAnimator(new DefaultItemAnimator());
        rvThingList.addItemDecoration(new DividerItemDecoration(ChangeThingListActivity.this, 1));
    }

    @Override
    protected void initData() {
        List<ThingBean> list = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            ThingBean thingBean = new ThingBean("T-Name" + i, "T-CODE" + i, "T-DESC" + i);
            list.add(thingBean);
        }
        eqpThingListAdapter = new EqpThingListAdapter(list, new DeleteCallback() {
            @Override
            public void onSuccess(ThingBean bean) {
                showToast("删除成功", true);
                eqpThingListAdapter.getData().remove(bean);
                eqpThingListAdapter.notifyDataSetChanged();
            }
        });
        eqpThingListAdapter.setFragmentManager(getSupportFragmentManager());
        rvThingList.setAdapter(eqpThingListAdapter);
    }

    @Override
    protected FreeUI_AddViewEntity getBaseEntity() {
        return new FreeUI_AddViewEntity("header", llMain);
    }

}
